using LitJson;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;


public class HttpMrg : Singleton<HttpMrg>
{
    public void Get(string url,JsonData values=null,Action<JsonData> callback = null)
    {
        if(values !=null)
        {
            url += "?";
            
        }
        StartCoroutine(this.GetRequest(url, callback));
    }
    IEnumerator GetRequest(string url, Action<JsonData> callback = null)
    {
        UnityWebRequest unityWeb = UnityWebRequest.Get(url);
        yield return unityWeb.SendWebRequest();
        if(unityWeb.isDone)
        {
            if(unityWeb.result == UnityWebRequest.Result.ConnectionError)
            {
                Debug.Log(unityWeb.result);
            }
            else
            {
                callback?.Invoke(new JsonData(unityWeb.downloadHandler.text));
            }
        }
    }
}